<?php

/**
 * Handles all aspects of the server on which this code runs,
 * including location
 *
 * @author Ben Rowe
 */
class Server 
{
	/**
	 * Singleton Handler
	 *
	 * @access public
	 * @return Server
	 */
	function &getInstance()
	{
		static $instance;
		if(!$instance) {
			$instance = new Server;
		}
		return $instance;
	}
	
	/**
	 * Retrieve the full uri to the install path.
	 * 
	 * @example returns http://domain.name/path/to/install/
	 * @access public
	 * @return string
	 */
	function getURI()
	{
		return $this->_buildURI();
	}
	
	/**
	 * Builds the URI string for the current install path
	 *
	 * @access private
	 * @return string
	 */
	function _buildURI()
	{
		$protocol	= 'http';
		$host		= $_SERVER['HTTP_HOST'];
		$uri		= $_SERVER['REQUEST_URI'];
		$path		= ($uri == '/index.php') ? null : substr(dirname($uri), 1);
		return $protocol.'://'.$host.'/'.$path .'/';
	}
}

?>